import gtk
import config
conf=config.config()
#import time

class progress_window(gtk.Window):
	def __init__(self, title, project_folder, list_photo, list_text, list_track, progress=None, preview=False):
		gtk.Window.__init__(self)
		self.set_position(gtk.WIN_POS_CENTER_ALWAYS)
 		
		self.bar=gtk.ProgressBar()
		self.tot_op=1
		self.current_op=-1
		self.op=gtk.Label()
		self.operations=gtk.Label()
		VBox=gtk.VBox(spacing=5)
		VBox.set_border_width(5)
		
		VBox.pack_start(self.bar, False)
		VBox.pack_start(self.operations)
		VBox.pack_end(self.op)
		
		self.add(VBox)
		self.set_title(title)
		self.set_size_request(400, 150)
 		self.set_icon_from_file(conf.picture_path+"logo.png")
 		self.show_all()
 		gtk.gdk.threads_init()
 		import make_video
 		mk_vid=make_video.make_video(project_folder, list_photo, list_text, list_track, self, preview=False)
 		mk_vid.start()
 		self.update("making the video")
 		gtk.main()
	
	def set_tot_operations(self, tot_op):
		self.tot_op=tot_op
	
	def update(self, op, unknow_len=False):
		self.current_op+=1
		per=self.current_op*100/self.tot_op
		if unknow_len:
			pass
		else:
			pass
		
		if op!="finish":
			self.bar.set_fraction(per*1.0/100.0)
			self.bar.set_text(str(per)+"%")
		else:
			self.hide()
			gtk.main_quit()
		self.op.set_text(op)
		self.operations.set_text(str(self.current_op)+ "/" + str(self.tot_op))
